function [TotalPayoff Buy Sell] = tradingStrategyVec2(rPortfolioTest, myVaRup, myVaRdown, V0)

    %% Strategy 2: buy when rPortfolioTest(i) under myVaRdown, sell when
    %  rPortfolioTest(i) upper myVaRdown

    TotalPayoff = 0;
    rBuy = 0; 
    Buy = []; Sell = [];
    for i = 1:length(rPortfolioTest)
        if (rPortfolioTest(i,:) <= myVaRdown(i) && rBuy == 0)
            rBuy = rPortfolioTest(i, :);
            Buy = [Buy; 1];     Sell = [Sell; 0];
        elseif (rPortfolioTest(i,:) >= myVaRup(i) && rBuy ~= 0)
            TotalPayoff = TotalPayoff + V0 * (rPortfolioTest(i,:) - rBuy);
            rBuy = 0;
            Buy = [Buy; 0];     Sell = [Sell; 1];
        else
            Buy = [Buy; 0];     Sell = [Sell; 0];
        end
    end
end